﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Autofac;
using Microsoft.AspNetCore.Mvc;
using NETCORE.Autofac.Service;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace NETCORE.Autofac.Controllers
{
    [Route("api/[controller]")]
    public class PayEachController : Controller
    {
        private IPayService _wxPayService;
        private IPayService _aliPayService;
        private IComponentContext _componentContext;//Autofac上下文

        public PayEachController(IComponentContext componentContext)
        {
            _componentContext = componentContext;

            //解释组件
            _wxPayService = _componentContext.ResolveNamed<IPayService>(typeof(WxPayService).Name);
            _aliPayService = _componentContext.ResolveNamed<IPayService>(typeof(AliPayService).Name);
        }


        [Route("GetPayType")]
        [HttpGet]
        public JsonResult GetPayType()
        {
            string paytype_wx = this._wxPayService.Pay();
            string paytype_ali = this._aliPayService.Pay();

            return new JsonResult(new { weixinPay = paytype_wx, aliPay = paytype_ali });
        }
    }
}
